package com.itbour.service.yjx.trade.impl;

import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.yjx.trade.YjxUserDocStatsDao;
import com.itbour.dto.tg.TypeInfoDto;
import com.itbour.dto.video.DesignUserDocDto;
import com.itbour.dto.video.VideoUserDocDto;
import com.itbour.dto.yjx.trade.YjxUserDocStatsDto;
import com.itbour.service.yjx.trade.YjxUserDocStatsService;

public class YjxUserDocStatsServiceImpl implements YjxUserDocStatsService {
	
	private  YjxUserDocStatsDao  yjxUserDocStatsDao;

	@Override
	public Page pageQueryStats(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		Page result = null;
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = yjxUserDocStatsDao.userDocStatsCnt(param);
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<YjxUserDocStatsDto> data = yjxUserDocStatsDao.userDocStatsInfo(param);
		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;
	}
	
	/** 分页获取视频模板  用户作品
	 */
	public Page pageUserViderDoc(Map<String, Object> parm, Integer pageNo,
			Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = yjxUserDocStatsDao.getUserVideoDocCnt(parm);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			parm.put("pageSize", pageSize);
			parm.put("skipResults", skipResults);
			List<VideoUserDocDto> data = yjxUserDocStatsDao.getUserVideoDoc(parm);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
		}
	}
	
	/**
	 * 分页 获取设计模板 用户作品
	 */
	public Page pageUserDesignDoc(Map<String, Object> parm, Integer pageNo,
			Integer pageSize) {
		try {
			Page result = null;
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = yjxUserDocStatsDao.getUserDesignDocCnt(parm);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			parm.put("pageSize", pageSize);
			parm.put("skipResults", skipResults);
			List<DesignUserDocDto> data = yjxUserDocStatsDao.getUserDesignDoc(parm);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
		}
	}
	
	@Override
	public boolean editShowViewCnt(Map<String, Object> parm) {
		try {
			yjxUserDocStatsDao.editItbTmplStatsInf(parm);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public boolean batchSetShowApplyCnt(Map<String, Object> parm){
		try {
			yjxUserDocStatsDao.batchSetShowApplyCnt(parm);
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	
	public List<TypeInfoDto> getTypeForCombo(Map<String, Object> param) {
		return yjxUserDocStatsDao.selectTypeInfo(param);
	}

	
	
	public YjxUserDocStatsDao getYjxUserDocStatsDao() {
		return yjxUserDocStatsDao;
	}

	public void setYjxUserDocStatsDao(YjxUserDocStatsDao yjxUserDocStatsDao) {
		this.yjxUserDocStatsDao = yjxUserDocStatsDao;
	}
}
